import os
import sys
from tanxi.client.Handler.Logger import log_info
print(sys.platform)

if sys.platform == 'linux':
    from gunicorn.app.wsgiapp import run
    log_info("linux服务启动...")

elif sys.platform == 'win32':
    from django.core.management import execute_from_command_line
    log_info("win服务启动...")
else:
    log_info("Unsupported platform")

# 启动django服务 win
def run_django_server():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demoPython.settings')
    sys.argv = ['manage.py', 'runserver', 'localhost:9121']  # 设置命令行参数
    execute_from_command_line(sys.argv)

# 启动django服务 linux
def run_gunicorn_server():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demoPython.settings')                       
    # 设置 Gunicorn 的命令行参数
    sys.argv = ['gunicorn', 'demoPython.wsgi:application', '--bind=localhost:9121']
    # 启动 Gunicorn
    run()


if __name__ == '__main__':

    if sys.platform == 'linux':
        run_gunicorn_server()
    elif sys.platform == 'win32':
        run_django_server()
    else:
        log_info("Unsupported platform")
